package com.minelx.statementsplus.common;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LongList {
	private final long[] elements;

	public LongList(long[] elements) {
		this.elements = elements;
	}

	public List<long[]> split(int partitionsCount) {
		List<long[]> result = new ArrayList<>();
		int lengthOfPartition = (int) Math.ceil(elements.length * 1.0f / partitionsCount);
		for (int at = 0; at < partitionsCount; at++) {
			if (at == partitionsCount - 1) { // last partition
				result.add(Arrays.copyOfRange(elements, at * lengthOfPartition, elements.length));
			} else { // general partition
				result.add(Arrays.copyOfRange(elements, at * lengthOfPartition, (at + 1) * lengthOfPartition));
			}
		}
		return result;
	}

	public static List<long[]> split(long[] source, int count) {
		return new LongList(source).split(count);
	}
}
